package com.innovations.inn.service.impl;

import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import com.innovations.inn.domain.OutcomesClassifyRelate;
import com.innovations.inn.mapper.OutcomesClassifyRelateMapper;
import com.innovations.inn.service.IOutcomesClassifyRelateService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 成果分类对应Service业务层处理
 *
 * @author dp
 * @date 2024-08-10
 */
@Service
public class OutcomesClassifyRelateServiceImpl implements IOutcomesClassifyRelateService {
    @Autowired
    private OutcomesClassifyRelateMapper outcomesClassifyRelateMapper;
    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询成果分类对应
     *
     * @param relateId 成果分类对应主键
     * @return 成果分类对应
     */
    @Override
    public OutcomesClassifyRelate selectOutcomesClassifyRelateByRelateId(Long relateId) {
        return outcomesClassifyRelateMapper.selectOutcomesClassifyRelateByRelateId(relateId);
    }

    /**
     * 查询成果分类对应列表
     *
     * @param outcomesClassifyRelate 成果分类对应
     * @return 成果分类对应
     */
    @Override
    public List<OutcomesClassifyRelate> selectOutcomesClassifyRelateList(OutcomesClassifyRelate outcomesClassifyRelate) {
        return outcomesClassifyRelateMapper.selectOutcomesClassifyRelateList(outcomesClassifyRelate);
    }

    /**
     * 新增成果分类对应
     *
     * @param outcomesClassifyRelate 成果分类对应
     * @return 结果
     */
    @Override
    public int insertOutcomesClassifyRelate(OutcomesClassifyRelate outcomesClassifyRelate) {
        return outcomesClassifyRelateMapper.insertOutcomesClassifyRelate(outcomesClassifyRelate);
    }

    /**
     * 新增成果分类对应列表
     *
     * @param outcomesClassifyRelateList 成果分类对应
     * @return 结果
     */
    @Override
    public int insertOutcomesClassifyRelateList(List<OutcomesClassifyRelate> outcomesClassifyRelateList) {
        try {
            outcomesClassifyRelateList.forEach(outcomesClassifyRelate -> {
                outcomesClassifyRelateMapper.insertOutcomesClassifyRelate(outcomesClassifyRelate);
            });
        } catch (Exception e) {
            return 0;
        }
        return 1;
    }

    /**
     * 修改成果分类对应
     *
     * @param outcomesClassifyRelate 成果分类对应
     * @return 结果
     */
    @Override
    public int updateOutcomesClassifyRelate(OutcomesClassifyRelate outcomesClassifyRelate) {
        return outcomesClassifyRelateMapper.updateOutcomesClassifyRelate(outcomesClassifyRelate);
    }

    /**
     * 批量删除成果分类对应
     *
     * @param relateIds 需要删除的成果分类对应主键
     * @return 结果
     */
    @Override
    public int deleteOutcomesClassifyRelateByRelateIds(Long[] relateIds) {
        return outcomesClassifyRelateMapper.deleteOutcomesClassifyRelateByRelateIds(relateIds);
    }

    /**
     * 删除成果分类对应信息
     *
     * @param relateId 成果分类对应主键
     * @return 结果
     */
    @Override
    public int deleteOutcomesClassifyRelateByRelateId(Long relateId) {
        return outcomesClassifyRelateMapper.deleteOutcomesClassifyRelateByRelateId(relateId);
    }

    /**
     * 删除成果分类对应信息--根据成果标识
     *
     * @param researchOutcomesId 成果标识
     * @return 结果
     */
    @Override
    public int deleteOutcomesClassifyRelateByOutcomesId(Long researchOutcomesId) {
        return outcomesClassifyRelateMapper.deleteOutcomesClassifyRelateByOutcomesId(researchOutcomesId);
    }

    /**
     * 实体数据补全
     *
     * @param outcomesClassifyRelate 实体
     * @param userId                 用户id
     * @param crateType              创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(OutcomesClassifyRelate outcomesClassifyRelate, Long userId, Integer crateType) {
        //主键
        if (outcomesClassifyRelate.getRelateId() == null || "".equals(outcomesClassifyRelate.getRelateId())) {
            outcomesClassifyRelate.setRelateId(idGeneratorSnowflake.nextId());
        }
    }

    /**
     * 查询成果分类对应-根据科研成果标识
     *
     * @param researchOutcomesId 成果标识
     * @return 成果分类对应
     */
    @Override
    public List<OutcomesClassifyRelate> selectOutcomesClassifyRelateByOutcomesId(Long researchOutcomesId) {
        return outcomesClassifyRelateMapper.selectOutcomesClassifyRelateByOutcomesId(researchOutcomesId);
    }
}
